import axios from 'axios';

// 配置基础 URL（根据你的后端地址调整）
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || '';
// 创建 axios 实例
const apiClient = axios.create({
  baseURL: API_BASE_URL,
  timeout: 10000,
  headers: {
    'Content-Type': 'application/json',
  },
});

apiClient.interceptors.request.use((config) => {
  const token = localStorage.getItem('token');
  if (token) {
    config.headers['Authorization'] = token; 
  }
  return config;
});

export const getInfo = async () => {
  try {
    const response = await apiClient.get('/enterprise/profile/get');
    return response.data;
  } catch (error) {
    throw new Error(error.response?.data?.message || '获取企业信息失败');
  }
};

export const submitInfo = async (data) => {
  try {
    const response = await apiClient.post('/enterprise/profile/submit', data);
    return response.data;
  } catch (error) {
    throw new Error(error.response?.data?.message || '提交企业信息失败');
  }
};

export const updateInfo = async (data) => {
  try {
    const response = await apiClient.put('/enterprise/profile/update', data);
    return response.data;
  } catch (error) {
    throw new Error(error.response?.data?.message || '更新企业信息失败');
  }
};

export const getInfoStatus = async () => {
  try {
    const response = await apiClient.get('/enterprise/profile/check-status');
    return response.data;
  } catch (error) {
    throw new Error(error.response?.data?.message || '获取企业信息状态失败');
  }
};
